package com.shop.service.impl;

import com.shop.mapper.EmployeeMapper;
import com.shop.pojo.Employee;
import com.shop.pojo.EmployeeExample;
import com.shop.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee checkLogin(String username) {

        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andNameEqualTo(username);

        List<Employee> employees = this.employeeMapper.selectByExample(employeeExample);

        if (employees != null && employees.size() > 0) {
            return employees.get(0);
        }

        return null;
    }


    @Override   // 查找【员工】
    public Employee findEmployeeByName(String name) {
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria createCriteria = example.createCriteria();
        createCriteria.andNameEqualTo(name);

        List<Employee> list = employeeMapper.selectByExample(example);

        if (list != null && list.size() > 0) {
            return list.get(0);
        }

        return null;
    }

    @Override   // 查找【管理者】
    public Employee findManagerByManagerId(Long managerId) {

        Employee employee = this.employeeMapper.selectByPrimaryKey(managerId);

        return employee;
    }

    @Override
    public Employee findEmployeeManagerByManagerId(long manageId) {

        return this.employeeMapper.selectByPrimaryKey(manageId);
    }
}
